<template>
  <el-form
    :model="noticForm"
    ref="noticForm"
    label-width="20px"
    :inline="true"
    :rules="rules"
  >
    <el-card>
      <h4 style="font-weight: 800">商品信息(第一行必填)</h4>
      <el-row>
        <el-form-item label="" prop="">
          <el-select
            v-model="fLive.productNo"
            clearable
            filterable
            remote
            :remote-method="getDatas"
            :loading="loading"
            placeholder="货号编码"
            @change="testAdd(fLive.productNo)"
            style="width: 150px"
          >
            <el-option
              v-for="item in options"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
          <el-select
            ref="selectRef"
            v-model="fLive.colorProperty"
            clearable
            filterable
            placeholder="选择颜色"
            @change="testColor(fLive.productNo, fLive.colorProperty)"
            style="width: 200px"
          >
            <el-option
              v-for="item in ColorLike"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
          <el-select
            ref="multiSelect"
            v-model="fLive.size"
            clearable
            placeholder="尺寸"
            style="width: 100px"
            @change="testSize(fLive.productNo, fLive.colorProperty, fLive.size)"
          >
            <el-option
              v-for="item in sizeList"
              :key="item.id"
              :label="item.size"
              :value="item.size"
            >
            </el-option>
          </el-select>
          <el-input
            ref="autoFocus"
            v-model="fLive.productNum"
            placeholder="购买数量"
            style="width: 110px"
            type="number"
            oninput="value=value.replace(/^0|[^0-9]/g,'')"
          ></el-input>
        </el-form-item>

        <el-form-item label="是否归还" prop="isReturn" label-width="100">
          <!-- <el-input v-model="formVFU.isReturn" placeholder="是否归还" /> -->
          <el-select
            v-model="fLive.isReturn"
            placeholder="请选择是否归还"
            clearable
            filterable
          >
            <el-option
              v-for="dict in dict.type.sys_one_zero"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="库存量：" prop="isReturn" label-width="100">
          {{ fLive.publicCanUseNum }}
        </el-form-item>
        <!-- <el-col :span="3">
          <el-form-item label="" prop="">
            <el-input
              v-model="demo"
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 10 }"
              placeholder="省市区地址、姓名、电话11位用空格分开!!"
            ></el-input>
            <el-button type="primary" size="mini" @click="addText"
              >识别</el-button
            >
          </el-form-item>
        </el-col> -->
      </el-row>
    </el-card>
    <el-card style="display: none">
      <h4 style="font-weight: 800">收货信息(必填)</h4>
      <el-col :span="16" :xs="24">
        <el-row>
          <el-form-item label="收件人" prop="recipient" label-width="70px">
            <el-input
              v-model="sampleTalentContact.recipient"
              placeholder="请输入收件人"
            />
          </el-form-item>
          <el-form-item label="电话" prop="phone" label-width="50px">
            <el-input
              v-model="sampleTalentContact.phone"
              placeholder="请输入电话"
            />
          </el-form-item>

          <el-form-item
            label="所在地区"
            prop="receiverState"
            label-width="80px"
          >
            <!-- <el-input v-model="sampleTalentContact.receiverState" placeholder="--请选择省份--" /> -->
            <el-select
              v-model="sampleTalentContact.receiverState"
              clearable
              placeholder="省"
              @change="seletekey($event, 'province')"
              style="width: 150px"
            >
              <el-option
                v-for="(val, key) in provinces"
                :key="key"
                :label="val"
                :value="val"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="receiverCity" label-width="50px">
            <!-- <el-input v-model="sampleTalentContact.receiverCity" placeholder="--请选择城市--" /> -->
            <el-select
              v-model="sampleTalentContact.receiverCity"
              clearable
              placeholder="市"
              @change="seletekey($event, 'city')"
              style="width: 150px"
            >
              <el-option
                v-for="(val, key) in citys"
                :key="key"
                :label="val"
                :value="val"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="" prop="receiverDistrict">
            <!-- <el-input v-model="sampleTalentContact.receiverDistrict" placeholder="--请选择县区--" /> -->
            <el-select
              v-model="sampleTalentContact.receiverDistrict"
              clearable
              placeholder="县区"
              @change="seletekey($event, 'area')"
              style="width: 150px"
              filterable
              allow-create
            >
              <el-option
                v-for="(val, key) in areas"
                :key="key"
                :label="val"
                :value="val"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="详细地址" prop="address" label-width="80px">
            <el-input
              v-model="sampleTalentContact.address"
              placeholder="请输入详细地址"
              style="width: 300px"
            />
          </el-form-item>
          <el-form-item
            prop="expressCompany"
            label="快递公司:"
            label-width="90px"
          >
            <!-- <el-input v-model="expressCompany"></el-input> -->
            <el-select
              v-model="expressCompany"
              placeholder="请选择快递公司"
              clearable
              filterable
            >
              <el-option
                v-for="dict in dict.type.sys_jst_sample_sf"
                :key="dict.label"
                :label="dict.label"
                :value="dict.label"
              />
            </el-select>
          </el-form-item>
        </el-row>
      </el-col>
      <!-- 
      <el-col :span="8" :xs="24">
        <el-form-item label="" prop="">
          <el-input
            v-model="demo"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 10 }"
            placeholder="省市区地址、姓名、电话11位用空格分开!!"
            style="width: 400px"
          ></el-input>
          <el-button type="primary" size="mini" @click="addText"
            >识别</el-button
          >
         
        </el-form-item>
      </el-col> -->
    </el-card>

    <!-- <el-row>
            <el-card>
                <el-form-item label="合作类型:" prop="platform" label-width="90px">
                    
                    <el-radio-group v-model="sampleTalentCooperateType" size="small" fill="#66b1ff"
                        @change="testsampleTalentCooperateType">

                        <el-radio :label="'note'">笔记合作</el-radio>
                        <el-radio :label="'live'">直播合作</el-radio>

                    </el-radio-group>
                </el-form-item>
                
            </el-card>
        </el-row> -->

    <el-card>
      <h4 style="font-weight: 800">
        联系地址列表<span style="font-weight: 500"
          >(已添加{{ noticForm.noticConfig.length }}个地址)</span
        >
      </h4>
      <el-col :span="21">
        <el-row
          v-for="(noticItem, index) in noticForm.noticConfig"
          :key="index"
        >
          <el-col
            :span="22"
            v-for="nameItem in noticItem.name"
            :key="nameItem.key"
          >
            <!-- <el-form-item prop="" label=" "> </el-form-item>
            <el-form-item prop="" label=" "> </el-form-item> -->
            <el-form-item prop="" label=" ">
              <el-input
                v-model="nameItem.recipient"
                placeholder="请输入收件人"
                style="width: 200px"
              />
              <el-input
                v-model="nameItem.phone"
                placeholder="请输入电话"
                style="width: 200px"
              />
              <el-select
                v-model="nameItem.receiverState"
                clearable
                placeholder="省"
                @change="seletekey($event, 'province')"
                style="width: 150px"
              >
                <el-option
                  v-for="(val, key) in provinces"
                  :key="key"
                  :label="val"
                  :value="val"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="receiverCity" label-width="50px">
              <!-- <el-input v-model="sampleTalentContact.receiverCity" placeholder="--请选择城市--" /> -->
              <el-select
                v-model="nameItem.receiverCity"
                clearable
                placeholder="市"
                @change="seletekey($event, 'city')"
                style="width: 150px"
              >
                <el-option
                  v-for="(val, key) in citys"
                  :key="key"
                  :label="val"
                  :value="val"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="receiverDistrict">
              <!-- <el-input v-model="sampleTalentContact.receiverDistrict" placeholder="--请选择县区--" /> -->
              <el-select
                v-model="nameItem.receiverDistrict"
                clearable
                placeholder="县区"
                @change="seletekey($event, 'area')"
                style="width: 150px"
                filterable
                allow-create
              >
                <el-option
                  v-for="(val, key) in areas"
                  :key="key"
                  :label="val"
                  :value="val"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="address" label-width="80px">
              <el-input
                v-model="nameItem.address"
                placeholder="请输入详细地址"
                style="width: 300px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <!-- <el-button type="primary" size="mini" @click="addDomain(noticItem)"
              >新增</el-button
            > -->
            <el-button
              type="danger"
              size="mini"
              @click.prevent="removeDomain(noticItem)"
              >删除</el-button
            >
            <!-- <el-button type="primary" size="mini" @click="getinventory">查询</el-button> -->
          </el-col>
        </el-row>
      </el-col>
      <!-- <el-col :span="3" :xs="24">
        <el-form-item label="" prop="">
          <el-input
            v-model="demo"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 10 }"
            placeholder="省市区地址、姓名、电话11位用空格分开!!"
            style="width: 200px"
          ></el-input>
          <el-button type="primary" size="mini" @click="addText"
            >识别</el-button
          >
          
        </el-form-item>
      </el-col> -->
    </el-card>
    <el-card>
      <h4 style="font-weight: 800">寄出理由</h4>

      <el-row :inline="true">
        <el-form-item label="申请理由" prop="" label-width="80px">
          <el-input
            v-model="innerApplyReason"
            placeholder="请输入申请理由"
            style="width: 300px"
          />
        </el-form-item>
        <el-form-item
          label="寄出归类"
          prop=""
          label-width="80px"
          v-if="this.sampleTalentCooperateType != 'VFU'"
        >
          <el-select
            v-model="sampleTalentCooperateType"
            placeholder="请选择"
            clearable
            filterable
          >
            <el-option
              v-for="dict in dict.type.sys_sample_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
          <!-- <el-input
            v-model="innerApplyReason"
            placeholder="请输入申请理由"
            style="width: 300px"
          /> -->
        </el-form-item>
        <!-- <el-form-item label="支付方式" prop="payMethod" label-width="80px">
          <el-input
            v-model="sampleTalentPay.payMethod"
            placeholder="请输入支付方式"
          />
        </el-form-item>
        <el-form-item label="支付账号" prop="payAccount" label-width="80px">
          <el-input
            v-model="sampleTalentPay.payAccount"
            placeholder="请输入支付账号"
          />
        </el-form-item>
        <el-form-item label="姓名" prop="payName" label-width="60px">
          <el-input
            v-model="sampleTalentPay.payName"
            placeholder="请输入姓名"
          />
        </el-form-item> -->
      </el-row>
    </el-card>
    <el-card>
      <h4 style="font-weight: 800">快递选择</h4>

      <el-row :inline="true">
        <el-form-item
          prop="expressCompany"
          label="快递公司:"
          label-width="90px"
        >
          <!-- <el-input v-model="expressCompany"></el-input> -->
          <el-select
            v-model="expressCompany"
            placeholder="请选择快递公司"
            clearable
            filterable
          >
            <el-option
              v-for="dict in dict.type.sys_jst_sample_sf"
              :key="dict.label"
              :label="dict.label"
              :value="dict.label"
            />
          </el-select>
        </el-form-item>
      </el-row>
    </el-card>

    <el-form-item style="width: 100%; text-align: center">
      <!-- <el-button @click="submitnote('noticForm')" type="primary"
        >笔记合作</el-button
      > -->
      <el-button @click="submitlive('noticForm')" type="primary"
        >发起寄样</el-button
      >
      <el-button @click="resetForm" style="margin-left: 10px"
        >一键清空</el-button
      >
    </el-form-item>
  </el-form>
</template>
<script>
import AddressParse from "address-parse";
//数据获取
import { pcaa } from "area-data";
import axios from "axios";
const util = require("@/api/sample/util.js");
// import { province } from '@/api/sample/map'
import {
  listTemplate,
  getTemplate,
  delTemplate,
  addTemplate,
  updateTemplate,
  addTemplateAndSecondry,
  addProNoColorSize,
  productNoLike,
} from "@/api/product/template";
import {
  listSecondry,
  getSecondry,
  delSecondry,
  addSecondry,
  updateSecondry,
  getInfoByName,
  productNoColorLike,
  listAll,
  colorLike,
} from "@/api/product/secondry";
import {
  listSample,
  getSample,
  delSample,
  addSample,
  updateSample,
  SampleTalentFirstAdd,
  SampleGiftBatchApply,
  inventory,
} from "@/api/sample/sample";
export default {
  name: "Ceshi",
  dicts: [
    "sys_product_qudao",
    "sys_product_size",
    "sys_product_coder",
    "sys_sample_sf",
    "sys_one_zero",
    "sys_sample_status",
    "sys_sample_name",
    "sys_sample_cj",
    "sys_jst_sample_sf",
    "sys_sample_type",
  ],
  props: {
    contactList: {
      type: Array,
      default: () => [],
    },
    sampleTalentCooperateType: {
      type: String,
      default: "",
    },
  },

  data() {
    return {
      // sampleTalentCooperateType: "live",
      innerApplyReason: "",
      fLive: {
        isReturn: "否",

        expressCompany: "中通快递",
        productNum: 1,
      },
      count: 1,
      sizeArr: [],
      //库存量
      num: "",
      demo: "",
      //省市区
      pcaaData: pcaa,
      // 区域数据
      provinces: pcaa["86"],
      citys: [],
      areas: [],
      //
      productNo: "",
      colorProperty: "",
      size: "",
      // 遮罩层
      loading: true,
      //模糊匹配
      sizeList: [],
      ColorLike: [],
      options: [], // 选项，从后端传递过来

      expressCompany: "中通快递",
      //data
      noticForm: {
        noticConfig: [
          {
            name: [
              {
                recipient: "",
                phone: "",
                receiverState: "",
                receiverCity: "",

                receiverDistrict: "",
                address: "",
                // value: "",
                // phone: "",
                // productNo: "",
                // colorProperty: "",
                // size: "",
                // productNum: "",
                // isReturn: "是",
                // id: 0,

                // expressCompany: "",
              },
            ],
            // phone: [
            //     {
            //         value: "",
            //     },
            // ],
          },
        ],
      },

      sampleTalentContact: {
        phone: "",
        receiverCity: "",
        receiverDistrict: "",
        receiverState: "",
        recipient: "",
        address: "",
      },
      sampleTalentInfo: {
        platform: "",
        platformId: "",
        talentLevel: "",
        xhsNickname: "",
        contactPerson: "",
        recommendSituation: "",
        reason: "",
        homeLink: "",
        fansNum: "",
        likeNum: "",
        cooperatePrice: "",
        talentStatus: "",
        contactWechat: "",
      },
      sampleTalentPay: {
        payAccount: "",
        payImage: "",
        payMethod: "",
        payName: "",
        platform: "",
      },

      // 表单校验
      rules: {
        productNo: [
          { required: true, message: "货号不能为空", trigger: "blur" },
        ],
        colorProperty: [
          { required: true, message: "颜色不能为空", trigger: "blur" },
        ],
        size: [{ required: true, message: "尺寸不能为空", trigger: "blur" }],
        // productNum: [
        //     { required: true, message: "数量不能为空", trigger: "blur" }
        // ],
        // platform: [
        //     { required: true, message: "平台名称不能为空", trigger: "blur" }
        // ],
        // platformId: [
        //     { required: true, message: "平台ID不能为空", trigger: "blur" }
        // ],
        // xhsNickname: [
        //     { required: true, message: "昵称不能为空", trigger: "blur" }
        // ],
        // phone: [
        //     { required: true, message: "电话不能为空", trigger: "blur" }
        // ],
      },
    };
  },
  created() {
    this.noticForm.noticConfig = [];
    this.contactList.forEach((item) => {
      this.noticForm.noticConfig.push({
        name: [
          {
            ...item,
          },
        ],
      });
    });

    // this.provincearr = province
    // this.getList();
  },
  methods: {
    // addText() {
    //   if (!this.demo) {
    //     this.$modal.msgError("请输入内容");
    //     return;
    //   }

    //   let address = this.demo.replace(/\s+/g, " ");
    //   console.log(JSON.stringify(address));
    //   axios({
    //     method: "get",
    //     url: "https://v.api.aa1.cn/api/api-kdjx/index.php",
    //     params: {
    //       msg: address,
    //     },
    //   }).then((res) => {
    //     console.log(JSON.stringify(res.data));
    //     let m = res.data.newslist[0];
    //     this.sampleTalentContact.phone = m.mobile ? m.mobile : "";
    //     this.sampleTalentContact.recipient = m.name ? m.name : "";
    //     this.sampleTalentContact.receiverState = m.province ? m.province : "";
    //     this.sampleTalentContact.receiverCity = m.city ? m.city : "";
    //     this.sampleTalentContact.receiverDistrict = m.district
    //       ? m.district
    //       : "";
    //     this.sampleTalentContact.address = m.detail;

    //     this.seletekey(this.sampleTalentContact.receiverState, "province");
    //     this.seletekey(this.sampleTalentContact.receiverCity, "city");
    //     this.seletekey(this.sampleTalentContact.receiverDistrict, "area");
    //   });
    // },
    addText() {
      if (!this.demo) {
        this.$modal.msgError("请输入内容");
        return;
      }

      let address = this.demo.replace(/\s+/g, " ");
      console.log(JSON.stringify(address));
      const result = AddressParse.parse(address);
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      if (!apply[0].recipient) {
        this.noticForm.noticConfig = [];
        this.noticForm.noticConfig.push({
          name: [
            {
              recipient: result[0].name ? result[0].name : "",
              phone: result[0].mobile ? result[0].mobile : "",
              receiverState: result[0].province ? result[0].province : "",
              receiverCity: result[0].city ? result[0].city : "",

              receiverDistrict: result[0].area ? result[0].area : "",
              address: result[0].details,
              //   key: Date.now(),
              createBy: null,
              createTime: null,
              id: null,
              isDelete: null,
              platform: null,
              platformId: null,
              remark: null,
              sampleTalentInfold: null,
              updateBy: null,
              updateTime: null,
              xhsNickname: null,
            },
          ],
        });
      } else {
        this.noticForm.noticConfig.push({
          name: [
            {
              recipient: result[0].name ? result[0].name : "",
              phone: result[0].mobile ? result[0].mobile : "",
              receiverState: result[0].province ? result[0].province : "",
              receiverCity: result[0].city ? result[0].city : "",

              receiverDistrict: result[0].area ? result[0].area : "",
              address: result[0].details,
              //   key: Date.now(),
              createBy: null,
              createTime: null,
              id: null,
              isDelete: null,
              platform: null,
              platformId: null,
              remark: null,
              sampleTalentInfold: null,
              updateBy: null,
              updateTime: null,
              xhsNickname: null,
            },
          ],
        });
      }
      return;
      this.sampleTalentContact.phone = result[0].mobile ? result[0].mobile : "";
      this.sampleTalentContact.recipient = result[0].name ? result[0].name : "";
      this.sampleTalentContact.receiverState = result[0].province
        ? result[0].province
        : "";
      this.sampleTalentContact.receiverCity = result[0].city
        ? result[0].city
        : "";
      this.sampleTalentContact.receiverDistrict = result[0].area
        ? result[0].area
        : "";
      this.sampleTalentContact.address = result[0].details;

      this.seletekey(this.sampleTalentContact.receiverState, "province");
      this.seletekey(this.sampleTalentContact.receiverCity, "city");
      this.seletekey(this.sampleTalentContact.receiverDistrict, "area");

      let obj = {
        fullAddress: this.demo,
        province: this.sampleTalentContact.receiverState,
        city: this.sampleTalentContact.receiverCity,
        district: this.sampleTalentContact.receiverDistrict,
        detailedAddress: this.sampleTalentContact.address,

        recipientPhone: this.sampleTalentContact.phone,
        recipientName: this.sampleTalentContact.recipient,
      };

      axios({
        method: "post",
        url: "http://47.107.129.160:9001/prod-api/product/parsing",
        // url: "http://47.97.123.182:1399/smAddress",
        data: obj,
      }).then((response) => {});
      //   this.sampleTalentContact.phone = res.data.phone ? res.data.phone : "";
      //   this.sampleTalentContact.recipient = res.data.name ? res.data.name : "";
      //   this.sampleTalentContact.receiverState = res.data.province
      //     ? res.data.province
      //     : "";
      //   this.sampleTalentContact.receiverCity = res.data.city
      //     ? res.data.city
      //     : "";
      //   this.sampleTalentContact.receiverDistrict = res.data.county
      //     ? res.data.county
      //     : "";
      //   this.sampleTalentContact.address = res.data.street
      //     ? res.data.street + res.data.address
      //     : res.data.address;

      //   this.seletekey(this.sampleTalentContact.receiverState, "province");
      //   this.seletekey(this.sampleTalentContact.receiverCity, "city");
      //   this.seletekey(this.sampleTalentContact.receiverDistrict, "area");
      // });
    },
    testsampleTalentCooperateType(val) {
      console.log(val);
      this.sampleTalentCooperateType = val;
    },

    submitlive() {
      //   if (!this.sampleTalentInfo.platform) {
      //     this.$modal.msgError("请输入平台名称");
      //     return;
      //   }
      //   if (!this.sampleTalentInfo.platformId) {
      //     this.$modal.msgError("请输入平台ID");
      //     return;
      //   }
      //   if (!this.sampleTalentInfo.xhsNickname) {
      //     this.$modal.msgError("请输入昵称");
      //     return;
      //   }
      //   if (!this.sampleTalentContact.phone) {
      //     this.$modal.msgError("请输入电话");
      //     return;
      //   }
      //   if (!this.sampleTalentContact.recipient) {
      //     this.$modal.msgError("请输入收件人");
      //     return;
      //   }
      //   if (!this.sampleTalentContact.receiverState) {
      //     this.$modal.msgError("请选择省份");
      //     return;
      //   }
      //   if (!this.sampleTalentContact.receiverCity) {
      //     this.$modal.msgError("请选择城市");
      //     return;
      //   }
      //   if (!this.sampleTalentContact.receiverDistrict) {
      //     this.$modal.msgError("请选择县区");
      //     return;
      //   }
      //   if (!this.sampleTalentContact.address) {
      //     this.$modal.msgError("请输入详细地址");
      //     return;
      //   }

      // == 'live'
      if (!this.innerApplyReason) {
        this.$modal.msgError("请输入申请理由");

        return;
      }
      console.log(this.sampleTalentCooperateType);
      // if (!this.sampleTalentCooperateType.includes('live')) {
      //     this.$modal.msgError('请选择直播类型')
      //     return
      // }
      // return
      console.log(JSON.stringify(this.noticForm.noticConfig));

      // this.noticForm.noticConfig.forEach(item => {
      //     note.push(item.name)
      // })
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      var live = [
        {
          ...this.fLive,
          innerApplyReason: this.innerApplyReason,
          expressCompany: this.expressCompany,
          id: null,
        },
      ];
      //   apply.forEach((item) => {
      //     live.push({ expressCompany: this.expressCompany, ...item });
      //   });

      console.log(JSON.stringify(live));
      var liveList = {
        sampleTalentCooperateType: this.sampleTalentCooperateType,
        sampleTalentApplyVOList: live,
        sampleTalentContactList: apply,
        // sampleTalentContact: { ...this.sampleTalentContact },
        // sampleTalentInfo: { ...this.sampleTalentInfo },
        // sampleTalentPay: { ...this.sampleTalentPay },
      };
      if (!liveList.sampleTalentApplyVOList[0].productNo) {
        this.$modal.msgError("请选择款式");
        return;
      }
      // if (!liveList.sampleTalentApplyVOList[0].colorProperty) {

      //     this.$modal.msgError('请选择颜色')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].size) {

      //     this.$modal.msgError('请选择尺寸')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].productNum) {

      //     this.$modal.msgError('请输入数量')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].isReturn) {

      //     this.$modal.msgError('请选择是否归还')
      //     return
      // }
      if (liveList.sampleTalentApplyVOList[1]) {
        if (!liveList.sampleTalentApplyVOList[1].productNo) {
          this.$modal.msgError("请选择第二个款式");
          return;
        }
      }

      // return
      console.log(JSON.stringify(liveList));
      SampleGiftBatchApply(liveList).then((res) => {
        console.log(res);
        if (res.msg == "操作完成！") {
          this.$modal.msgSuccess("操作完成");
          // this.data = {};
          // window.location.reload();
          //清空数据
          this.resetForm();
          // return;
          this.$router.push({
            path: "/sample/sampleApply",
            // query: { platformId: this.sampleTalentInfo.platformId },
          });
          // location.reload();
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },
    resetForm() {
      this.noticForm = {
        noticConfig: [
          {
            name: [
              {
                productNo: "",
                colorProperty: "",
                size: "",
                productNum: "",
                isReturn: "是",
                id: 0,
              },
            ],
          },
        ],
      };
      this.sampleTalentContact = {};
      this.sampleTalentInfo = {};
      this.sampleTalentPay = {};
    },
    submitnote() {
      if (!this.sampleTalentInfo.platform) {
        this.$modal.msgError("请输入平台名称");
        return;
      }
      if (!this.sampleTalentInfo.platformId) {
        this.$modal.msgError("请输入平台ID");
        return;
      }
      if (!this.sampleTalentInfo.xhsNickname) {
        this.$modal.msgError("请输入昵称");
        return;
      }
      if (!this.sampleTalentContact.phone) {
        this.$modal.msgError("请输入电话");
        return;
      }
      if (!this.sampleTalentContact.recipient) {
        this.$modal.msgError("请输入收件人");
        return;
      }
      if (!this.sampleTalentContact.receiverState) {
        this.$modal.msgError("请选择省份");
        return;
      }
      if (!this.sampleTalentContact.receiverCity) {
        this.$modal.msgError("请选择城市");
        return;
      }
      if (!this.sampleTalentContact.receiverDistrict) {
        this.$modal.msgError("请选择县区");
        return;
      }
      if (!this.sampleTalentContact.address) {
        this.$modal.msgError("请输入详细地址");
        return;
      }

      // if (!this.sampleTalentPay.payMethod) {

      // this.$modal.msgError('请输入支付方式')
      // return
      // }
      // if (!this.sampleTalentPay.payMethod) {

      // this.$modal.msgError('请输入支付方式')
      // return
      // }
      // if (!this.sampleTalentPay.payMethod) {

      //     this.$modal.msgError('请输入支付方式')
      //     return
      // }
      // if (!this.sampleTalentPay.payMethod) {

      //     this.$modal.msgError('请输入支付方式')
      //     return
      // }
      // if (!this.sampleTalentCooperateType.includes('note')) {
      //     this.$modal.msgError('请选择笔记类型')
      //     return
      // }
      // var apply = this.noticForm.noticConfig.map(item => item.name[0])
      var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      console.log(JSON.stringify(apply));
      var live = [];
      apply.forEach((item) => {
        live.push({ expressCompany: this.expressCompany, ...item });
      });

      var liveList = {
        sampleTalentCooperateType: "note",
        sampleTalentApplyVOList: live,
        sampleTalentContact: { ...this.sampleTalentContact },
        sampleTalentInfo: { ...this.sampleTalentInfo },
        sampleTalentPay: { ...this.sampleTalentPay },
      };
      console.log(JSON.stringify(liveList));
      if (!liveList.sampleTalentApplyVOList[0].productNo) {
        this.$modal.msgError("请选择款式");
        return;
      }
      // if (!liveList.sampleTalentApplyVOList[0].colorProperty) {

      //     this.$modal.msgError('请选择颜色')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].size) {

      //     this.$modal.msgError('请选择尺寸')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].productNum) {

      //     this.$modal.msgError('请输入数量')
      //     return
      // }
      // if (!liveList.sampleTalentApplyVOList[0].isReturn) {

      //     this.$modal.msgError('请选择是否归还')
      //     return
      // }
      if (liveList.sampleTalentApplyVOList[1]) {
        if (!liveList.sampleTalentApplyVOList[1].productNo) {
          this.$modal.msgError("请选择第二个款式");
          return;
        }
      }
      // return
      SampleTalentFirstAdd(liveList).then((res) => {
        console.log(res);
        if (res.msg == "操作完成！") {
          this.$modal.msgSuccess("操作完成");
          this.$router.push({
            path: "/sample/sample",
            // query: { platformId: this.sampleTalentInfo.platformId },
          });
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },

    // 新增
    removeDomain(item) {
      var index = this.noticForm.noticConfig.indexOf(item);
      if (index == "0") {
        // 还有一个的时候提示不能删除
        this.$message({
          message: "不能删除了",
          type: "error",
        });
        return false;
      }
      if (index !== -1 && index !== "0") {
        this.noticForm.noticConfig.splice(index, 1);
      }
    },
    // 表单新增
    addDomain(item) {
      this.$modal.msgError("暂不支持");
      return;
      console.log(
        JSON.stringify(this.noticForm.noticConfig[0].name[0].isReturn)
      );
      var m = item.name[0];
      if (!m.productNo) {
        this.$modal.msgError("请选择款式");
        return;
      }
      if (!m.colorProperty) {
        this.$modal.msgError("请选择颜色");
        return;
      }
      if (!m.size) {
        this.$modal.msgError("请选择尺寸");
        return;
      }
      if (!m.productNum) {
        this.$modal.msgError("请输入数量");
        return;
      }
      if (!m.isReturn) {
        this.$modal.msgError("请选择是否归还");
        return;
      }
      // var i = 0
      // if(m.isReturn){

      // }
      this.noticForm.noticConfig.push({
        name: [
          {
            // value: "",

            // phone: "",
            productNo: "",
            colorProperty: "",
            size: "",
            productNum: "",
            isReturn: this.noticForm.noticConfig[0].name[0].isReturn,
            id: this.count++,
            // num: "",
            // expressCompany: "",
            key: Date.now(),
          },
        ],
        // phone: [
        //     {
        //         value: "",
        //         key: Date.now() + "2",
        //     },
        // ],
      });
    },
    getinput() {
      console.log(JSON.stringify(this.noticForm.noticConfig));
    },
    //修改对话框
    /* 获取颜色列表 */
    getSize(key) {
      console.log(JSON.stringify(key));
      // this.loading = true;
      // return
      // listAll({ productNo: this.form.productNo, colorProperty: this.form.colorProperty }).then((res) => {
      //     // this.loading = false;
      //     this.sizeList = res
      //     console.log(JSON.stringify(res));
      // });
    },

    /* 获取颜色列表 */
    getData(key) {
      console.log(JSON.stringify(key));
      // this.loading = true;
      // return
      // colorLike(key).then((res) => {
      //     // this.loading = false;
      //     this.ColorLike = res.data;
      //     console.log(JSON.stringify(this.ColorLike));
      // });
    },
    getinventory() {
      inventory({
        productNo: this.productNo,
        colorProperity: this.colorProperty,
        size: this.form.size,
      }).then((res) => {
        // console.log(JSON.stringify(res.data));
        if (res.code == 200) {
          this.num = res.data[0].virtual_qty;
        } else {
          this.$modal.msgError(res.msg);
        }
      });
    },
    testNum(index) {
      // this.num = JSON.parse(localStorage.getItem("num"))
    },
    // 打开加载层
    openLoading2() {
      this.$modal.loading("正在读取聚水潭库存，请稍侯！");
    },
    testSize(productNo, colorProperty, size) {
      // var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      // const hasEmptyProductNo = apply.some(
      //   (product) => product.productNo == ""
      // );
      // if (hasEmptyProductNo) {
      //   this.$modal.msgError("检查货号编码是否为空");
      //   return;
      // }
      // const hasEmptycolorProperty = apply.some(
      //   (product) => product.colorProperty == ""
      // );
      // if (hasEmptycolorProperty) {
      //   this.$modal.msgError("检查颜色属性是否为空");
      //   return;
      // }
      // const hasEmptysize = apply.some((product) => product.size == "");
      // if (hasEmptysize) {
      //   this.$modal.msgError("检查尺寸是否为空");
      //   return;
      // }
      // console.log(JSON.stringify(key));
      // this.size = key;
      // console.log(this.count);
      // console.log(index);
      this.openLoading2();
      inventory({
        productNo: productNo,
        colorProperity: colorProperty,
        size: size,
      }).then((res) => {
        this.$modal.closeLoading();

        if (res.code == 200) {
          if (res.data.length > 0) {
            // if (res.data[0].publicCanUseNum < 5) {
            //   this.$alert(
            //     `货号:${this.productNo}，颜色：${this.colorProperty}，码数：${this.size}，库存不足，仅${res.data[0].publicCanUseNum}件，请慎重申请。`,
            //     "温馨提醒",
            //     {
            //       confirmButtonText: "我知道了",
            //       // showConfirmButton: false,
            //     }
            //   ).then(() => {});
            // }
            this.fLive.publicCanUseNum = res.data[0].publicCanUseNum;
            // console.log(JSON.stringify(this.sizeArr[index]));
            // console.log(JSON.stringify(this.sizeArr));
            this.$forceUpdate();
          } else {
            this.$alert("该商品编码聚水潭不存在，请核对。", "提示", {
              confirmButtonText: "我知道了",
              // showConfirmButton: false,
            }).then(() => {});
            // this.$modal.msgError("该商品编码聚水潭不存在，请核对。");
          }
        } else {
          this.$alert("该商品编码聚水潭不存在，请核对。", "提示", {
            confirmButtonText: "我知道了",
            // showConfirmButton: false,
          }).then(() => {});
          // this.$modal.msgError(res.msg);
        }
      });
      // setTimeout(() => {
      //   this.$refs[multiSelect].blur();
      // }, 50);

      // this.$refs[multiSelect].blur();
    },
    /* 获取尺寸列表 */
    testColor(productNo, colorProperty) {
      listAll({ productNo: productNo, colorProperty: colorProperty }).then(
        (res) => {
          // this.loading = false;
          this.sizeList = res;
          console.log(JSON.stringify(res));
        }
      );
    },
    /* 获取颜色列表 */
    testAdd(key) {
      this.productNo = key;
      console.log();
      if (!key) {
        return;
      }
      productNoColorLike({ productNo: key }).then((res) => {
        // this.loading = false;
        this.ColorLike = res.data;
        console.log(JSON.stringify(this.ColorLike));
      });
    },

    /* 获取货号列表 */
    getDatas(key) {
      console.log(JSON.stringify(key));
      this.loading = true;
      // return
      productNoLike(key).then((res) => {
        this.loading = false;
        this.options = res.data;
        console.log(JSON.stringify(this.options));
      });
    },
    //修改对话框
    //添加颜色列表获得焦点
    onFocus() {
      this.getData();

      this.getSize();
      // if (!this.form.colorProperty) {
      //     this.$selectRef.value.blur() //就是这一句，
      // }
    },
    seletekey(e, type) {
      if (e) {
        switch (type) {
          case "province":
            Object.keys(this.provinces).filter((item) => {
              if (this.provinces[item] === e) {
                this.citys = this.pcaaData[item];
              }
            });
            break;
          case "city":
            Object.keys(this.citys).filter((item) => {
              if (this.citys[item] === e) {
                this.areas = this.pcaaData[item];
              }
            });
            break;
          case "area":
            this.sampleTalentContact.receiverDistrict = e;
            this.$forceUpdate();
            break;
        }
      }
    },
  },
};
</script>
